//using System;
//using System.Collections.Generic;
//using System.Linq;
//using Microsoft.Xna.Framework;
//using Microsoft.Xna.Framework.Audio;
//using Microsoft.Xna.Framework.Content;
//using Microsoft.Xna.Framework.GamerServices;
//using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Input;
//using Microsoft.Xna.Framework.Media;

//namespace Services
//{
//  public class Particle
//  {
//    public float Age, AgingSpeed;
//    public Vector3 Position, Velocity, Gravity;
//    public float MaxAge;
//    public float Size;
//    public bool IsActive;
//    public Color Color;
//  }

//  public class ParticleSystem<T> : CameraConsumer where T : Particle
//  {
//    public ParticleSystem(Game game, string TexturePath)
//      : base(game)
//    {
//      this.texture_path = TexturePath;
//    }

//    public T AddParticle(T p)
//    {
//      particles.Add(p);
//      return p;
//    }

//    string texture_path;
//    Texture2D texture;
//    List<T> particles = new List<T>(1000);
//    SpriteBatch spriteBatch;

//    protected override void LoadContent()
//    {
//      spriteBatch = new SpriteBatch(Game.GraphicsDevice);
//      texture = Game.Content.Load<Texture2D>(texture_path);

//      base.LoadContent();
//    }

//    public override void Update(GameTime gameTime)
//    {
//      var dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
//      for (int i = 0; i < particles.Count; i++)
//      {
//        if (particles[i].Age <= 0.0f || particles[i].IsActive == false)
//        {
//          particles.RemoveAt(i);
//          i--;
//          continue;
//        }
//        particles[i].Age -= particles[i].AgingSpeed * dt;
//        particles[i].Position += (particles[i].Velocity + particles[i].Gravity) * dt;
//      }

//      base.Update(gameTime);
//    }

//    public override void Draw(GameTime gameTime)
//    {
//      spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive);
//      foreach (var p in particles)
//      {
//        var p2d = GraphicsDevice.Viewport.Project(p.Position, projection, view, Matrix.Identity);
//        var size = p.Size * max_depth / Vector3.Distance(p.Position, EyePosition);
//        var color = p.Color.ToVector4();
//        color.W = p.Age / p.MaxAge;
//        spriteBatch.Draw(texture, new Vector2(p2d.X, p2d.Y), null, new Color(color), 0.0f,
//          new Vector2(texture.Width/2,texture.Height/2), size, SpriteEffects.None, 0.0f);
//      }
//      spriteBatch.End();

//      base.Draw(gameTime);
//    }

//    public void Reset()
//    {
//      particles.Clear();
//    }
//  }
//}